package com.ebt.m.share;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.ebt.m.R;

public class ShareUnit extends LinearLayout {

    Context mContext;
    private int mImage;
    private String mText;

    private TextView share_unit_text;
    private ImageView share_unit_image;

    public ShareUnit(Context context) {
        this(context, null);
    }

    public ShareUnit(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public ShareUnit(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        mContext = context;
        View contentView = inflate(context, R.layout.share_unit, this);

        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.shareUnit);

        final int count = a.getIndexCount();
        for (int i = 0; i < count; ++i) {
            int attr = a.getIndex(i);
            switch (attr) {
                case R.styleable.shareUnit_shareUnitText:
                    mText = a.getString(attr);
                    break;
                case R.styleable.shareUnit_shareUnitImage:
                    mImage = a.getResourceId(attr, 0);
                    break;
            }
        }
        a.recycle();

        share_unit_text = (TextView) contentView.findViewById(R.id.share_unit_text);
        share_unit_image = (ImageView) contentView.findViewById(R.id.share_unit_image);
        share_unit_text.setTextColor(Color.BLACK);
        if (mText != null && mText.length() > 0) {
            share_unit_text.setText(mText);
        }
        if (mImage > 0) {
            share_unit_image.setImageResource(mImage);
        }
    }

    public void setShareUnitText(String text) {
        mText = text;
        if (share_unit_text != null) {
            share_unit_text.setText(mText);
        }
    }

    public void setShareUnitImage(int imageId) {
        mImage = imageId;
        if (share_unit_image != null) {
            share_unit_image.setImageResource(mImage);
        }
    }

    public String getShareUnitText() {
        return mText;
    }

    public int getShareUnitImage() {
        return mImage;
    }

    public TextView getShareUnitTextView() {
        return share_unit_text;
    }

    public ImageView getShareUnitImageButton() {
        return share_unit_image;
    }
}
